package com.xiaocikuai.smallchunks.utils.resultd;

import java.util.HashMap;
import java.util.Map;

public class Resultd {
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<>();
    public Boolean getSuccess(){ return success; }
    public void setSuccess(Boolean success){ this.success = success; }
    public Integer getCode() { return code;}
    public void setCode(Integer code){ this.code = code; }
    public String getMessage() { return message; }

    public void setMessage(String message){ this.message = message;}

    public Map<String, Object> getData(){ return data; }

    public void setData(Map<String, Object> data){ this.data = data;}

    //把构造方法私有
    private Resultd(){}
    //成功静态方法
    public static Resultd ok() {
        Resultd r = new Resultd();
        r.setSuccess(true);
        r.setCode(ResultdCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static Resultd error() {
        Resultd r = new Resultd();
        r.setSuccess(false);
        r.setCode(ResultdCode.ERROR);
        r.setMessage("失败");
        return r;
    }

    public Resultd success(Boolean success) {
        this.setSuccess(success);
        return this;
    }
    public Resultd message(String message){
        this.setMessage(message);
        return this;
    }



    public Resultd code(Integer code) {
        this.setCode(code);
        return this;
    }

    public Resultd data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }


    public Resultd data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
